﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using CloudClip.ExtensionMethod;

namespace CloudClip.Clip
{
    public class TextClipUnit : IClipUnit
    {
        public TextClipUnit(string sText)
        {
            _ClipText = sText;
        }

        private string _ClipText = string.Empty;

        public string ToText()
        {
            return _ClipText;
        }

        public string ToIntroduction()
        {
            const int iLength = 40;
            string sIntroductionText = _ClipText;
            sIntroductionText = Regex.Replace(sIntroductionText, "[\r\n\t]", " ", RegexOptions.IgnoreCase);
            sIntroductionText = Regex.Replace(sIntroductionText, "  +", " ", RegexOptions.IgnoreCase);
            sIntroductionText = sIntroductionText.Trim();

            if (sIntroductionText.Length < iLength)
            {
                return sIntroductionText;
            }else
            {
                return sIntroductionText.SubstringEx2(iLength).Trim() + "...";
            }
        }

        public void SetClipboard()
        {
            Clipboard.SetDataObject(_ClipText);
        }
    }

    /// <summary>
    /// [實驗中]同步List那邊還不支援還原檔案,所以不開放
    /// </summary>
    [Obsolete]
    public class FileClipUnit : IClipUnit
    {
        public FileClipUnit(StringCollection stringCollection)
        {
            _stringCollection = stringCollection;
        }

        private StringCollection _stringCollection = new StringCollection();

        public string ToText()
        {
            return _stringCollection[0];
        }

        public string ToIntroduction()
        {
            const int iLength = 40;
            string sIntroductionText = string.Format("[{0} File] - {1}",_stringCollection.Count, Path.GetFileName(_stringCollection[0]));
            
            if (sIntroductionText.Length < iLength)
            {
                return sIntroductionText;
            }
            else
            {
                return sIntroductionText.SubstringEx2(iLength).Trim() + "...";
            }
        }

        public void SetClipboard()
        {
            Clipboard.SetFileDropList(_stringCollection);
        }
    }
}
